package com.neusoft.my12306.utils;

import com.neusoft.my12306.service.ISysinfoRolesRService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GlobalFilterConfiguration {
    @Autowired
    JwtUtil jwtUtil;

    @Autowired
    ISysinfoRolesRService  sysinfoRolesRService;
    @Bean
    public FilterRegistrationBean RegistTest1(){
        //通过FilterRegistrationBean实例设置优先级可以生效
        //通过@WebFilter无效
        FilterRegistrationBean bean = new FilterRegistrationBean();
        MyFilter1 myFilter1 = new MyFilter1();
        myFilter1.setJwtUtil(jwtUtil);
        bean.setFilter(myFilter1);//注册自定义过滤器
        bean.setName("flilter1");//过滤器名称
        bean.addUrlPatterns("/*");//过滤所有路径
        bean.setOrder(1);//优先级，最顶级
        return bean;
    }

    @Bean
    public FilterRegistrationBean registAuthTokenFilter(){
        //通过FilterRegistrationBean实例设置优先级可以生效
        //通过@WebFilter无效
        FilterRegistrationBean bean = new FilterRegistrationBean();
        AuthTokenFilter authTokenFilter = new AuthTokenFilter();
        authTokenFilter.setJwtUtil(jwtUtil);
        bean.setFilter(authTokenFilter);//注册自定义过滤器
        bean.setName("authTokenFilter");//过滤器名称
        bean.addUrlPatterns("/*");//过滤所有路径
        bean.setOrder(2);//优先级，最顶级
        return bean;
    }


    @Bean
    public FilterRegistrationBean registAuthPathFilter(){
        //通过FilterRegistrationBean实例设置优先级可以生效
        //通过@WebFilter无效
        FilterRegistrationBean bean = new FilterRegistrationBean();
        AuthPathFilter filter = new AuthPathFilter();
        filter.setService(sysinfoRolesRService);
        bean.setFilter(filter);//注册自定义过滤器
        bean.setName("authPathFilter");//过滤器名称
        bean.addUrlPatterns("/*");//过滤所有路径
        bean.setOrder(3);//优先级，最顶级
        return bean;
    }






}
